package com.wm;

/**
 * @ClassName:Person
 * @Description:
 * @Author:Deamer
 * @Date:2022/1/3 16:27
 **/
public class Person {
    private int age;
    private String name;

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    // finalize()是Object里面的一个方法，当一个堆空间中的对象没有被栈空间变量指向的时候，这个对象会等待被java回收
    // 调用对象的此方法可以判断对象的是否被回收了
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("Person---finalize");
    }

    // 对象默认比较的是对象的内存地址
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj instanceof Person) {
            Person person = (Person) obj;
            return this.age == person.age;
        }
        return false;
    }
}
